home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #2 / Amiga Plus CD - 1999 - No. 2.iso / System-Boost / Workbench / ToolManager / Source / Converter / misc.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  3KB  |  118 lines

  1. /*
  2.  * misc.c  V3.1
  3.  *
  4.  * ToolManager preferences file converter misc. routines
  5.  *
  6.  * Copyright (C) 1990-98 Stefan Becker
  7.  *
  8.  * This source code is for educational purposes only. You may study it
  9.  * and copy ideas or algorithms from it for your own projects. It is
  10.  * not allowed to use any of the source codes (in full or in parts)
  11.  * in other programs. Especially it is not allowed to create variants
  12.  * of ToolManager or ToolManager-like programs from this source code.
  13.  *
  14.  */
  15.  
  16. #include "converter.h"
  17.  
  18. /* Local data structures */
  19. struct IDListEntry {
  20.  struct Node ile_Node;
  21.  ULONG       ile_ID;
  22. };
  23.  
  24. /* Convert one string config parameter and return pointer to next string */
  25. #define DEBUGFUNCTION ConvertConfigString
  26. char *ConvertConfigString(char *buf, struct IFFHandle *iffh, ULONG id)
  27. {
  28.  ULONG len = strlen(buf) + 1;
  29.  
  30.  MISC_LOG(LOG3(Entry, "Chunk 0x%08lx String '%s' (0x%08lx)", id, buf, buf))
  31.  
  32.  /* Push, write and pop chunk */
  33.  return(((PushChunk(iffh, 0, id, len) == 0) &&
  34.          (WriteChunkBytes(iffh, buf, len) == len) &&
  35.          (PopChunk(iffh) == 0)) ? (buf + len) : NULL);
  36. }
  37.  
  38. /* Add on entry to the ID list */
  39. #undef  DEBUGFUNCTION
  40. #define DEBUGFUNCTION AddToIDList
  41. BOOL AddIDToList(struct MinList *l, const char *name, ULONG id)
  42. {
  43.  ULONG               len = sizeof(struct IDListEntry) + strlen(name) + 1;
  44.  struct IDListEntry *ile;
  45.  
  46.  MISC_LOG(LOG4(Entry, "List 0x%08lx Name '%s' (0x%08lx) ID 0x%08lx",
  47.                l, name, name, id))
  48.  
  49.  /* Allocate ID list entry */
  50.  if (ile = GetVector(len)) {
  51.  
  52.   MISC_LOG(LOG2(Allocated, "Entry 0x%08lx Length %ld", ile, len))
  53.  
  54.   /* Initialize list entry */
  55.   ile->ile_Node.ln_Name = (char *) (ile + 1);
  56.   ile->ile_ID           = id;
  57.  
  58.   /* Copy name */
  59.   strcpy(ile->ile_Node.ln_Name, name);
  60.  
  61.   /* Add entry to list */
  62.   AddTail((struct List *) l, (struct Node *) ile);
  63.  }
  64.  
  65.  return(ile != NULL);
  66. }
  67.  
  68. /* Find ID in list */
  69. #undef  DEBUGFUNCTION
  70. #define DEBUGFUNCTION FindIDInList
  71. ULONG FindIDInList(struct MinList *l, const char *name)
  72. {
  73.  ULONG               rc  = 0;
  74.  struct IDListEntry *ile = (struct IDListEntry *) GetHead(l);
  75.  
  76.  MISC_LOG(LOG3(Entry, "List 0x%08lx Name '%s' (0x%08lx)", l, name, name))
  77.  
  78.  /* Scan list */
  79.  for (ile = (struct IDListEntry *) l->mlh_Head;
  80.       ile->ile_Node.ln_Succ;
  81.       ile = (struct IDListEntry *) ile->ile_Node.ln_Succ)
  82.  
  83.   /* Name found? */
  84.   if (strcmp(name, ile->ile_Node.ln_Name) == 0) {
  85.  
  86.    /* Get ID */
  87.    rc = ile->ile_ID;
  88.  
  89.    /* Leave loop */
  90.    break;
  91.   }
  92.  
  93.  MISC_LOG(LOG1(Result, "%ld", rc))
  94.  
  95.  return(rc);
  96. }
  97.  
  98. #undef  DEBUGFUNCTION
  99. #define DEBUGFUNCTION FreeIDList
  100. void FreeIDList(struct MinList *l)
  101. {
  102.  struct IDListEntry *ile;
  103.  
  104.  MISC_LOG(LOG1(List, "0x%08lx", l))
  105.  
  106.  /* Scan list */
  107.  while (ile = (struct IDListEntry *) RemTail((struct List *) l)) {
  108.  
  109.   MISC_LOG(LOG1(Entry, "0x%08lx", ile))
  110.  
  111.   /* Free entry */
  112.   FreeVector(ile);
  113.  }
  114. }
  115.  
  116. /* Include global miscellaneous code */
  117. #include "/global_misc.c"
  118.